package server1;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;

public class Request implements ServletRequest {
    private InputStream input;
    private String uri;
    private String request;
    public Request(InputStream input) {
        this.input = input;
    }

    public void parse() {
        byte[] buffer = new byte[4096];
        int len = 0;
        try {
             len = input.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
            len = -1;
        }
        StringBuffer sb = new StringBuffer(4096);
        for (int i = 0; i < len; i++) {
            sb.append((char)buffer[i]);
        }
        request = sb.toString();
        System.out.println("request:============================================");
        System.out.println(request);
        System.out.println("====================================================");
        parseUri();
    }
    private void parseUri() {
        String request = this.request;
        int beginIndex = request.indexOf(' ');
        if (beginIndex != -1) {
            int endIndex = request.indexOf(' ', beginIndex + 1);
            if (endIndex > beginIndex) {
                this.uri = request.substring(beginIndex + 1, endIndex);
            }
        }
    }
    public String getUri() {
        return this.uri;
    }

    @Override
    public Object getAttribute(String s) {
        return null;
    }

    @Override
    public Enumeration getAttributeNames() {
        return null;
    }

    @Override
    public String getCharacterEncoding() {
        return null;
    }

    @Override
    public void setCharacterEncoding(String s) throws UnsupportedEncodingException {

    }

    @Override
    public int getContentLength() {
        return 0;
    }

    @Override
    public String getContentType() {
        return null;
    }

    @Override
    public ServletInputStream getInputStream() throws IOException {
        return null;
    }

    @Override
    public String getParameter(String s) {
        return null;
    }

    @Override
    public Enumeration getParameterNames() {
        return null;
    }

    @Override
    public String[] getParameterValues(String s) {
        return new String[0];
    }

    @Override
    public Map getParameterMap() {
        return null;
    }

    @Override
    public String getProtocol() {
        return null;
    }

    @Override
    public String getScheme() {
        return null;
    }

    @Override
    public String getServerName() {
        return null;
    }

    @Override
    public int getServerPort() {
        return 0;
    }

    @Override
    public BufferedReader getReader() throws IOException {
        return null;
    }

    @Override
    public String getRemoteAddr() {
        return null;
    }

    @Override
    public String getRemoteHost() {
        return null;
    }

    @Override
    public void setAttribute(String s, Object o) {

    }

    @Override
    public void removeAttribute(String s) {

    }

    @Override
    public Locale getLocale() {
        return null;
    }

    @Override
    public Enumeration getLocales() {
        return null;
    }

    @Override
    public boolean isSecure() {
        return false;
    }

    @Override
    public RequestDispatcher getRequestDispatcher(String s) {
        return null;
    }

    @Override
    public String getRealPath(String s) {
        return null;
    }
}
